package com.flute.framework.configuration;

import java.util.ArrayList;
import java.util.List;

import com.flute.framework.index.fieldbuilder.ScoreField;
import com.flute.framework.search.result.AbstractResultParser;
import com.flute.framework.search.sort.SorterInformation;
import com.flute.framework.search.strategy.ISearchStrategy;

public class SearchInformation {
	private List<ISearchStrategy> strategyList;
	private List<SorterInformation> sorterList;
	private AbstractResultParser parser;

	public SearchInformation() {
		this.strategyList = new ArrayList<ISearchStrategy>();
		this.sorterList = new ArrayList<SorterInformation>();
	}

	public void addSorterInformation(SorterInformation sorterInformation) {
		this.sorterList.add(sorterInformation);
	}

	public List<SorterInformation> getSorterList() {
		return sorterList;
	}

	public void setSorterList(List<SorterInformation> sorterList) {
		this.sorterList = sorterList;
	}

	public AbstractResultParser getParser() {
		return parser;
	}

	public void setParser(AbstractResultParser parser) {
		this.parser = parser;
	}

	public void addSearchStrategy(ISearchStrategy strategy) {
		this.strategyList.add(strategy);
	}

	public List<ISearchStrategy> getStrategyList() {
		return strategyList;
	}

	public void setStrategyList(List<ISearchStrategy> strategyList) {
		this.strategyList = strategyList;
	}

	public int getScorer(int sorterName) {
		int selected = -1;
		int used = -1;
		for (SorterInformation sorter : sorterList) {
			if (sorter.getName() == sorterName) {
				selected = sorter.getName();
			}
			if (sorter.isUsed()) {
				used = sorter.getName();
			}
		}

		if (selected != -1) {
			return selected;
		} else if (used != -1) {
			return used;
		} else {
			return ScoreField.DEFAULT_SCORE;
		}
	}
}